package com.ljh.myaiagent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class LoveAppVectorStoreConfig {
    // 这里可以添加向量存储的配置，例如使用哪种向量数据库，连接信息等
    @Resource
    private LoveAppDocumentLoader loveAppDocumentLoader;

    @Bean
    VectorStore loveAppVectorStore(EmbeddingModel dashScopeEmbeddingModel) {
        // 这里可以根据加载的文档创建向量存储
        // SimpleVectorStore 是Spring AI提供的一个内置的、简单的内存向量存储实现
        SimpleVectorStore simpleVectorStore = SimpleVectorStore
                .builder(dashScopeEmbeddingModel).build();
        List<Document> documents = loveAppDocumentLoader.loadMarkdowns();
        simpleVectorStore.add(documents);
        return simpleVectorStore; // 返回实际的向量存储实例
    }
}
